﻿using AutoMapper;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.JSInterop.Infrastructure;
using System.Net.NetworkInformation;
using System.Runtime.InteropServices;
using System.Security.Cryptography.Xml;
using ZhiJiao.Dal;
using ZhiJiao.Models.Entities;
using ZhiJiao.Models.Entities.Enums;
using ZhiJiao.Service.Abstracts;
using ZhiJiao.Service.Dto;

namespace ZhiJiao.Service.Services
{
    public class EvaluationService : IEvaluationService
    {
        private readonly BackJson _res;
        private readonly ZJDbContext _db;
        private readonly ICurrentUser _currentUser;
        private readonly IMapper _mapper;
        private readonly IHttpContextAccessor _httpContextAccessor;
        private readonly IFileUploadService _fileUploadService;
        private readonly IWebHostEnvironment _webHost;

        public EvaluationService(BackJson backJson,
                                  ZJDbContext zJDbContext,
                                  ICurrentUser currentUser,
                                  IMapper mapper,
                                  IHttpContextAccessor httpContextAccessor,
                                  IFileUploadService fileUploadService,
                                  IWebHostEnvironment webHost)
        {
            _res = backJson;
            _db = zJDbContext;
            _currentUser = currentUser;
            _mapper = mapper;
            _httpContextAccessor = httpContextAccessor;
            _fileUploadService = fileUploadService;
            _webHost = webHost;
        }

        /// <summary>
        /// 获取测评列表
        /// </summary>
        public async Task<BackJson> GetEvaluationList(string? filterName)
        {
            try
            {
                var query = _db.Evaluations
                                .Include(e => e.Instruction)
                                .AsQueryable();
                if (!string.IsNullOrEmpty(filterName))
                {
                    query= query.Where(e => e.Name.Contains(filterName));
                }
                query = query.Where(e => e.Instruction.Id == _currentUser.User.Instruction!.Id!);
                var list = await query.ToListAsync();
                _res.code = 0;
                _res.data = _mapper.Map<List<Evaluation>, List<EvaluationDto>>(list);
            }
            catch (Exception e)
            {
                _res.code = 1;
                _res.data = e.Message;
            }

            return _res;
        }

        /// <summary>
        /// 加载单个测试     
        /// </summary>
        public async Task<BackJson> GetEval(long id)
        {
            var eval = await _db.Evaluations.Include(e => e.ListImage).Include(e => e.MainImage).Include(e => e.DetailImages).FirstOrDefaultAsync(u => u.Id == id && u.Instruction.Id == _currentUser.User.Instruction!.Id!);
            if (eval != null)
            {
                _res.code = 0;
                _res.data = _mapper.Map<Evaluation, EvaluationDto>(eval);
            }
            else
            {
                _res.code = 1;
                _res.msg = "您所要编辑的测评已被删除！";
            }

            return _res;
        }

        /// <summary>
        /// 保存
        /// </summary>
        /// <returns></returns>
        public async Task<BackJson> Save(EvaluationDto dto)
        {
            try
            {
                var eval = await _db.Evaluations.FirstOrDefaultAsync(e=>e.Id==dto.Id);
                if (eval != null)
                {
                    eval.Name = dto.Name!;
                    eval.IsFree = dto.IsFree;
                    eval.NormalPrice = dto.NormalPrice;
                    eval.SilverPrice = dto.SilverPrice;
                    eval.GoldPrice = dto.GoldPrice;
                    eval.DiamondPrice = dto.DiamondPrice;
                    eval.LastTime = dto.LastTime;
                    eval.Status= dto.Status;
                    eval.Introduction = dto.Introduction;
                    _db.Update(eval);
                    int count = await _db.SaveChangesAsync();
                    _res.code = 0;
                    _res.msg = "测评保存成功";
                }
                else
                {
                    _res.code = 1;
                    _res.msg = "编辑的测评不存在或已被删除";
                }
            }
            catch (Exception e)
            {
                _res.code = 1;
                _res.msg = e.Message;
            }
            return _res;
        }

        /// <summary>
        /// 提交
        /// </summary>
        public async Task<BackJson> Submit(EvaluationDto evalDto)
        {
            try
            {
                if (evalDto.Status == EvaluationStatus.Create)
                {
                    evalDto.Status = EvaluationStatus.InUse;
                }
                var res = await Save(evalDto);
                if (res.code==0)
                {
                    _res.code = 0;
                    _res.msg = "提交成功！";
                }
            }
            catch (Exception e)
            {
                _res.code = 1;
                _res.msg = e.Message;
            }
            return _res;
        }

        /// <summary>
        ///  创建测评对象
        /// </summary>
        public async Task<BackJson> CreateEvaluation()
        {
            Evaluation eval = new Evaluation();
            eval.Instruction = await _db.Instructions.FirstAsync(i => i.Id == _currentUser.User.Instruction!.Id);
            eval.Status = EvaluationStatus.Create;
            eval.Name = "新建测试";
            eval.CreatedTime = DateTime.Now;
            var evalEntity = (await _db.Evaluations.AddAsync(eval)).Entity;
            _db.SaveChanges();
            _res.code = 0;
            _res.data = _mapper.Map<Evaluation, EvaluationDto>(evalEntity);
            return _res;
        }


        public async Task<BackJson> DeleteEvaluationg(long id)
        {
            try
            {
                var eval = await _db.Evaluations.FirstOrDefaultAsync(e => e.Id == id);
                if (eval != null)
                {
                    _db.Evaluations.Remove(eval);
                    _db.SaveChanges();
                    _res.code = 0;
                    _res.msg = "测评已被删除";
                }
                else
                {
                    _res.code = 0;
                    _res.msg = "您所要删除的测评不存在！";
                }

            }
            catch (Exception e)
            {
                _res.code = 1;
                _res.msg = e.Message;
            }
            return _res;
        }


        public async Task<BackJson> UploadImage(long eavlId, string actionType)
        {
            try
            {
                var evaluation = await _db.Evaluations.Include(e => e.DetailImages).Include(e => e.ListImage).Include(e => e.MainImage).FirstAsync(e => e.Id == eavlId);
                var image = await _fileUploadService.UploadMultiImageAsync();
                ZJImage zJImage = null;
                if (actionType == "mainImage") // 主图,轮播图
                {
                    image.EvaluationId = eavlId;
                    zJImage = _db.ZJImages.Add(_mapper.Map<ImageDto, ZJImage>(image)).Entity;
                    evaluation.MainImage = zJImage;
                }
                else if (actionType == "listIamge") // 列表图
                {
                    image.EvaluationId = eavlId;
                    zJImage = _db.ZJImages.Add(_mapper.Map<ImageDto, ZJImage>(image)).Entity;
                    evaluation.ListImage = zJImage;
                }
                else if (actionType == "detailIamges") // 详情图
                {
                    if (evaluation.DetailImages == null)
                    {
                        evaluation.DetailImages = new List<ZJImage>();
                    }
                    image.EvaluationId = eavlId;
                    zJImage = _db.ZJImages.Add(_mapper.Map<ImageDto, ZJImage>(image)).Entity;
                    evaluation.DetailImages.Add(zJImage);
                }
                else
                {
                    throw new Exception("请指定上传图片类型！");
                }
                _db.Evaluations.Update(evaluation);
                await _db.SaveChangesAsync();
                image.Id = zJImage.Id;
                _res.code = 0;
                _res.data = image;
                _res.msg = "文件上传成功!";
            }
            catch (Exception e)
            {
                _res.code = 1;
                _res.msg = e.Message;
            }

            return _res;
        }

        /// <summary>
        /// 删除图片
        /// </summary>
        public async Task<BackJson> DeleteImageAsync(long id, string actionType)
        {
            var image = _db.ZJImages.FirstOrDefault(i => i.Id == id);
            if (image != null)
            {
                try
                {
                    var eval = await _db.Evaluations.FirstAsync(e => e.Id == image.EvaluationId);
                    switch (actionType)
                    {
                        case "listImage":
                            eval.ListImage = null;
                            break;

                        case "mainImage":
                            eval.MainImage = null;
                            break;

                        case "detailImages":
                            eval.DetailImages!.Remove(image);
                            break;

                        default:
                            break;
                    }
                    _db.ZJImages.Remove(image);
                    _fileUploadService.DeleteImage(image);
                    int count = await _db.SaveChangesAsync();
                    if (count > 0)
                    {
                        _res.code = 0;
                        _res.msg = "图片删除成功";
                    }
                    else
                    {
                        _res.code = 1;
                        _res.msg = "图片删除失败，请联系开发人员";
                    }
                }
                catch (Exception e)
                {
                    _res.code = 1;
                    _res.msg = e.Message;
                }
            }
            else
            {
                _res.code = 0;
                _res.msg = "图片已被删除";
            }
            return _res;
        }

        /// <summary>
        ///  获取测评模块
        /// </summary>
        public async Task<BackJson> GetEvaluationParts(long id)
        {
            var list = await _db.EvaluationParts
                        .Include(e => e.Questions.OrderBy(q => q.Number))
                        .Where(e => e.Evaluation.Id == id)
                        .OrderBy(e => e.Order)
                        .ToListAsync();

            _res.code = 0;
            _res.data = list.Select(e => new
            {
                id = e.Id,
                order = e.Order,
                name = e.Name,
            });
            return _res;
        }


        /// <summary>
        /// 删除模块
        /// </summary>
        public async Task<BackJson> DeletePart(long id)
        {
            var part = await _db.EvaluationParts.FirstOrDefaultAsync(e => e.Id == id);
            try
            {
                if (part != null)
                {
                    _db.EvaluationParts.Remove(part);
                    await _db.SaveChangesAsync();
                    _res.code = 0;
                    _res.msg = "测评模块删除成功；";
                }
                else
                {
                    _res.code = 0;
                    _res.msg = "测评模块已不存在！";
                }
            }
            catch (Exception e)
            {
                _res.code = 1;
                _res.msg = e.Message;
            }
           
            return _res;
        }

        /// <summary>
        /// 获取测试题
        /// </summary>
        public async Task<BackJson> GetQuestion(long id)
        {
            var question = await _db.Questions.Include(q=>q.EvaluationPart).Include(q=>q.Options).Include(q=>q.Result).FirstOrDefaultAsync(q => q.Id == id);
            if (question != null)
            {
                var questionDto = _mapper.Map<Question, QuestionDto>(question);
                _res.code = 0;
                _res.data = questionDto;
            }
            else
            {
                _res.code = 1;
                _res.msg = "测试题不存在";
            }

            return _res;
        }

        /// <summary>
        /// 获取检查模块
        /// </summary>
        public async Task<BackJson> GetEvalPart(long id)
        {
            var evalPart = await _db.EvaluationParts.Include(p => p.Evaluation).Include(p=>p.Questions).ThenInclude(q=>q.Result).FirstOrDefaultAsync(e => e.Id == id);
            if (evalPart != null)
            {
                var evalPartDto = _mapper.Map<EvaluationPart, EvaluationPartDto>(evalPart);
                _res.code = 0;
                _res.data = evalPartDto;
            }
            else
            {
                _res.code = 1;
                _res.msg = "测试模块不存在";
            }
            return _res;
        }

        /// <summary>
        /// 保存测试模块
        /// </summary>
        public async Task<BackJson> SavePart(EvaluationPartDto part, string actionType)
        {
            EvaluationPart? evaluationPart = null;
            if (actionType == "创建")
            {
                evaluationPart = new EvaluationPart();
                evaluationPart.Order = part.Order;
                evaluationPart.Name = part.Name!;
                evaluationPart.Content = part.Content!;
                evaluationPart.TotalScore = 0;
                evaluationPart.Evaluation = await _db.Evaluations.FirstAsync(e => e.Id == part.evalId);
                await _db.EvaluationParts.AddAsync(evaluationPart);
                _db.SaveChanges();
                _res.code = 0;
                _res.msg = "测试模块添加成功！";
                _res.data = new
                {
                    id = evaluationPart.Id,
                    order = evaluationPart.Order,
                    name = evaluationPart.Name,
                    content = evaluationPart.Content
                };

            }
            else if (actionType == "编辑")
            {
                evaluationPart = await _db.EvaluationParts.FirstOrDefaultAsync(e => e.Id == part.Id);
                if (evaluationPart != null)
                {
                    evaluationPart.Order = part.Order;
                    evaluationPart.Name = part.Name!;
                    evaluationPart.Content = part.Content!;
                    if (evaluationPart.Questions != null && evaluationPart.Questions.Count > 0)
                    {
                        int totalScore = 0;
                        foreach (var question in evaluationPart.Questions)
                        {
                            totalScore += question.Score;
                        }
                        evaluationPart.TotalScore = totalScore;
                    }
                    else
                    {
                        evaluationPart.TotalScore = 0;
                    }
                    _db.SaveChanges();
                    _res.code = 0;
                    _res.data = new
                    {
                        id = evaluationPart.Id,
                        order = evaluationPart.Order,
                        content = evaluationPart.Content,
                        totalScore = evaluationPart.TotalScore
                    };
                    _res.msg = "测试模块保存成功！";
                }
                else
                {
                    _res.code = 1;
                    _res.msg = "您所编辑的测评已被删除或不存在！";
                }
            }
            return _res;
        }


        /// <summary>
        /// 保存测试题
        /// </summary>
        public async Task<BackJson> SaveQuestion(QuestionDto dto, string actionType)
        {
            if (actionType == "创建")
            {
                Question question = _mapper.Map<QuestionDto, Question>(dto);
                var evalPart = await _db.EvaluationParts.FirstAsync(e => e.Id == dto.EvaluationPartId);
                question.EvaluationPart = evalPart;
                await _db.Questions.AddAsync(question);
                await _db.SaveChangesAsync();
                _res.code = 0;
                _res.data = question.Id;
                _res.msg = "测试题创建成功！";
            }
            else if (actionType == "编辑")
            {
                var question = await _db.Questions.Include(q=>q.EvaluationPart).ThenInclude(p=>p.Questions).FirstOrDefaultAsync(q => q.Id == dto.Id);
                if (question != null)
                {
                    question.Number = dto.Number;
                    question.Content = dto.Content != null ? dto.Content : "";
                    question.QuestionType = dto.QuestionType;
                    question.Score = dto.Score;
                    question.Result = new List<Option>();
                    if (!string.IsNullOrEmpty(dto.ResultIds))
                    {
                        var ids= dto.ResultIds.Split(",");
                        foreach (var id in ids) 
                        {
                            var option = await _db.Options.FirstOrDefaultAsync(o => o.Id == Convert.ToInt64(id));
                            if (option != null)
                            {
                                question.Result.Add(option);
                            }
                        }
                    }
                    var questionList=question.EvaluationPart.Questions;
                    int partScore = 0;
                    if (questionList != null && questionList.Count > 0)
                    {
                        foreach (var item in questionList)
                        {
                            partScore += item.Score;
                        }
                    }
                    question.EvaluationPart.TotalScore = partScore;
                    // _db.EvaluationParts.Update(question.EvaluationPart);
                    _db.Update(question);
                    await _db.SaveChangesAsync();
                    _res.code = 0;
                    _res.data = question.Id;
                    _res.msg = "保存成功";
                }
                else
                {
                    _res.code = 1;
                    _res.msg = "您所编辑的测试题不存在，可能已被删除！";
                }
            }
            return _res;
        }

        /// <summary>
        /// 获取模块测试题集合
        /// </summary>
        public async Task<BackJson> GetPartQuestions(long partId)
        {
            var part = await _db.EvaluationParts.Include(p=>p.Questions).ThenInclude(q=>q.Options).FirstOrDefaultAsync(part => part.Id == partId);
            if (part != null)
            {
                var list = part.Questions.OrderBy(q => q.Number).ToList();
                _res.code = 0;
                _res.data = _mapper.Map<List<Question>, List<QuestionDto>>(list);
            }
            else
            {
                _res.code = 1;
                _res.msg = "测试模板不存在或已经被删除！";
            }
            return _res;
        }

        /// <summary>
        ///  删除测试题
        /// </summary>
        public async Task<BackJson> DeleteQuestion(long id)
        {
            var question = await _db.Questions.FirstOrDefaultAsync(q => q.Id == id);
            if (question != null)
            {
                _db.Questions.Remove(question);
                _db.SaveChanges();
                _res.code = 0;
                _res.msg = "测试题删除成功";
            }
            else
            {
                _res.code = 1;
                _res.msg = "删除的测试题不存在或已被其他用户删除";
            }

            return _res;
        }

        /// <summary>
        ///  生成选项标签 
        /// </summary>
        public async Task<BackJson> GenerateOptionLabel(long questionId)
        {
            var question = await _db.Questions.Include(q=>q.Options).FirstOrDefaultAsync(q => q.Id == questionId);
            List<Option> options = null;
            if (question != null)
            {
                options = question.Options;
                if (options != null && options.Count > 0)
                {
                    var list = options.OrderBy(o => o.Label).ToList();
                    _res.code = 0;
                    _res.data= Convert.ToInt32(list[list.Count - 1].Label) + 1;
                }
                else
                {
                    _res.code = 0;
                    _res.data = 0;
                }
            }
            else
            {
                _res.code = 1;
                _res.msg = "您所编辑的测试题不存在或已被其他用户删除！";
            }
            return _res;
        }

        /// <summary>
        /// 加载问题选项集合
        /// </summary>
        public async Task<BackJson> GetQuestionOptions(long questionId)
        {
            var question = await _db.Questions.Include(e=>e.Options).FirstOrDefaultAsync(q => q.Id == questionId);
            if (question != null)
            {
                List<OptionDto> list = null;
                if (question.Options != null)
                {
                    list = _mapper.Map<List<Option>, List<OptionDto>>(question.Options.OrderBy(o=>o.Label).ToList());
                }
                else
                { 
                    list = new List<OptionDto>();
                }
                _res.code = 0;
                _res.data = list;
            }
            else
            {
                _res.code = 1;
                _res.msg = "您所操作的测试题不存在，或已被删除。";
            }
            return _res;
        }

        /// <summary>
        /// 获取选项
        /// </summary>
        public async Task<BackJson> GetOption(long id)
        {
            var option = await _db.Options.FirstOrDefaultAsync(o=>o.Id==id);
            if (option != null)
            {
                _res.code = 0;
                _res.data = _mapper.Map<Option, OptionDto>(option);
            }
            else
            {
                _res.code = 1;
                _res.msg = "选项不存在";
            }
            return _res;
        }

        /// <summary>
        /// 保存选项
        /// </summary>
        public async Task<BackJson> SaveOption(OptionDto dto)
        {
            Option? option = null;
            if (dto.Id == null) // 新建
            {
                var question = await _db.Questions.FindAsync(dto.QuestionId);
                if (question != null)
                {
                    option = new Option();
                    option.Question = question;
                    option.Context = dto.Context;
                    option.QuestionId = dto.QuestionId;
                    option.Label = dto.Label;
                    _db.Options.Add(option);
                    question.Options.Add(option);
                    _db.SaveChanges();
                    _res.code = 0;
                    _res.msg = "选项创建成功";
                }
                else
                {      
                    _res.code = 1;
                    _res.msg = "您所编辑的测试题不存在或已被删除！";
                }
            }
            else // 修改
            {
                var question = await _db.Questions.FindAsync(dto.QuestionId);
                if (question != null)
                {
                    option = await _db.Options.FirstOrDefaultAsync(o=>o.Id==dto.Id);
                    if (option != null)
                    {
                        option.Question = question;
                        option.Label = dto.Label;
                        option.Context = dto.Context;
                        _db.Options.Update(option);
                        _db.SaveChanges();
                        _res.code = 0;
                        _res.msg = "选项保存成功";
                    }
                    else
                    {
                        _res.code = 1;
                        _res.msg = "您所编辑的选项不存在或已被删除";
                    }
                }
            }
            return _res;
        }

        /// <summary>
        /// 删除选项
        /// </summary>
        public async Task<BackJson> DeleteOption(long id)
        { 
            var option = await _db.Options.FirstOrDefaultAsync(x => x.Id == id);
            if (option != null)
            {
                _db.Options.Remove(option);
                _db.SaveChanges();
                _res.code = 0;
                _res.msg = "选项删除成功";
            }
            else
            {
                _res.code = 1;
                _res.msg = "删除的选项不存在或已被删除";
            }

            return _res;
        }

        /// <summary>
        /// 保存问题答案
        /// </summary>
        public async Task<BackJson> SaveQuestionResult(long questionId, string ids)
        {
            try
            {
                var question = await _db.Questions.Include(q => q.Result).FirstOrDefaultAsync(q => q.Id == questionId);
                if (question != null)
                {
                    question.Result.Clear();
                    if (!string.IsNullOrEmpty(ids))
                    {
                        foreach (var item in ids.Split(','))
                        {
                            var option = await _db.Options.FirstOrDefaultAsync(o => o.Id == Convert.ToInt64(item));
                            if (option != null)
                            {
                                question.Result.Add(option);
                            }
                        }
                    }
                    await _db.SaveChangesAsync();
                    _res.code = 0;
                    _res.msg = "测试题答案已保存";
                }
                else
                {
                    _res.code = 1;
                    _res.msg = "您所操作的测试题不存在或已被删除";
                }
            }
            catch (Exception e)
            {
                _res.code = 1;
                _res.msg = e.Message;
            }
            return _res;
        }

        /// <summary>
        /// 获取机构列表
        /// </summary>
        /// <param name="id"></param>
        /// <param name=""></param>
        /// <returns></returns>
        public async Task<BackJson> GetInsRules(long insId,long evalId)
        {
            try
            {
                var list = await _db.Rules.Where(r => r.Instruction.Id == insId && r.IsActive).ToListAsync();
                var evaluation = await _db.Evaluations.Include(e=>e.Rules).FirstOrDefaultAsync(e => e.Id == evalId);
                if (evaluation != null)
                {
                    if (evaluation.Rules != null && evaluation.Rules.Count > 0)
                    {
                        _res.data = list.Select( e => new
                        {
                            id = e.Id,
                            name = e.Name,
                            ruleType = Convert.ToInt32(e.RuleType),
                            memberLevel = Convert.ToInt32(e.MemberLevel),
                            wxShareCount = e.WXShareCount,
                            dyShareCount = e.DYShareCount,
                            isIn = IsInEvalRules(e, evaluation.Rules)
                        });
                    }
                    else
                    {
                        _res.data = list.Select(e=> new
                        {
                            id = e.Id,
                            name = e.Name,
                            ruleType = Convert.ToInt32(e.RuleType),
                            memberLevel = Convert.ToInt32(e.MemberLevel),
                            wxShareCount = e.WXShareCount,
                            dyShareCount = e.DYShareCount,
                            isIn = false
                        });
                    }
                    _res.code = 0;
                }
            }
            catch (Exception e)
            { 
                _res.code=1;
                _res.msg = e.Message;
            }
            return _res;
        }

        /// <summary>
        /// 是否在测评的规则中
        /// </summary>
        /// <param name="insRules"></param>
        /// <param name="evalRules"></param>
        /// <returns></returns>
        public  bool IsInEvalRules(Rule insRule,List<Rule> evalRules)
        {
            bool res = false;
            foreach (var rule in evalRules)
            {
                if (rule.Id == insRule.Id)
                {
                    res = true;
                    break;
                }
            }

            return res;
        }

        /// <summary>
        /// 从测评中移除参与规则
        /// </summary>
        public async Task<BackJson> RemoveRuleFromEval(long evalId, long ruleId)
        {
            var eval = await _db.Evaluations.Include(e => e.Rules).FirstOrDefaultAsync(e => e.Id == evalId);
            if (eval != null)
            {
                var rule = await _db.Rules.FirstOrDefaultAsync(r => r.Id == ruleId);
                if (rule != null)
                {
                    eval.Rules.Remove(rule);
                    await _db.SaveChangesAsync();
                    _res.code = 0;
                    _res.msg = "参与规则移除成功";
                }
                else
                {
                    _res.code = 1;
                    _res.msg = "当前机构下不存在此参与规则或已被删除";
                }
            }
            else
            {
                _res.code = 1;
                _res.msg = "操作的测评不存在或已被删除";
            }
            return _res;
        }

        /// <summary>
        /// 将参与规格加入测评
        /// </summary>
        public async Task<BackJson> AddRuleToEval(long evalId, long ruleId)
        {
            var eval = await _db.Evaluations.Include(e => e.Rules).FirstOrDefaultAsync(e => e.Id == evalId);
            if (eval != null)
            {
                var rule = await _db.Rules.FirstOrDefaultAsync(r => r.Id == ruleId);
                if (rule != null)
                {
                    eval.Rules.Add(rule);
                    await _db.SaveChangesAsync();
                    _res.code = 0;
                    _res.msg = "参与规则移除成功";
                }
                else
                {
                    _res.code = 1;
                    _res.msg = "当前机构下不存在此参与规则或已被删除";
                }
            }
            else
            {
                _res.code = 1;
                _res.msg = "操作的测评不存在或已被删除";
            }
            return _res;
        }
    }
}
